package it.giuseppetrisciuoglio.lyrics.service.facebook;

import java.io.IOException;
import java.net.*;
import java.net.Proxy.Type;

import org.apache.http.HttpHost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.restfb.DefaultWebRequestor;

@Component
public class ProxyWebRequestor extends DefaultWebRequestor {

	@Autowired
	private HttpHost proxy;
	
	public ProxyWebRequestor() {
		super();
	}

	@Override
	protected HttpURLConnection openConnection(URL url) throws IOException {
		InetSocketAddress isa = new InetSocketAddress(proxy.getHostName(), proxy.getPort());
		Proxy proxy = new Proxy(Type.HTTP, isa);
		return (HttpURLConnection) url.openConnection(proxy);
	}

}
